package tool;

import aboutbook.Book;
import aboutbook.BookList;

import java.util.Scanner;

public class Add implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("添加方法");
        Scanner book = new Scanner(System.in);

        if(bookList.isFull()){
            System.out.println("书已满，不能继续添加");
        }

        System.out.println("请输入你要新增图书的书名");
        String bookname = book.nextLine();

        System.out.println("请输入你要新增图书的作者");
        String bookauthor = book.nextLine();

        System.out.println("请输入你要新增图书的价格");
        int bookprice = book.nextInt();

        System.out.println("请输入你要新增图书的类型");
        String booktype = book.nextLine();

        //把新书的属性 全部放进 新创建的对象（通过构造方法 快速初始化）
        Book book1 = new Book(bookname,bookauthor,bookprice,booktype);

        int currentnum = bookList.getBebooks();
        //把新书放进 数组里
        bookList.setBooks(currentnum,book1);

        //把 数组中的 计数器 +1
        bookList.setBebooks(currentnum + 1);

        System.out.println("新增图书成功");

    }

}
